<template >
  <div class="ordermanage-container">
    <breadcrumb style="position: absolute;width:100%;"></breadcrumb>
    <div class="content">
      <div class="query">
        <div class="margin_right_20">
          订单编号:&nbsp;
          <el-input
            v-model="orderNo"
            placeholder="请输入订单编号"
            style="width:200px;height:30px;"
            @keyup.enter.native="get_orderList(1)"
          ></el-input>
        </div>
        <div class="margin_right_20">
          用户ID:&nbsp;
          <el-input
            v-model="userNo"
            placeholder="请输入用户ID"
            style="width:100px;height:30px;"
            @keyup.enter.native="get_orderList(1)"
          ></el-input>
        </div>
        <div class="margin_right_20">
          商品名称:&nbsp;
          <el-input
            v-model="goodsName"
            placeholder="请输入商品名称"
            style="width:180px;height:30px;"
            @keyup.enter.native="get_orderList(1)"
          ></el-input>
        </div>
        <div class="margin_right_20">
          订单所属活动:&nbsp;
          <el-select v-model="positionId" style="width: 130px;">
            <el-option
              v-for="item in options1"
              :key="item.id"
              :label="item.position"
              :value="item.id"
            ></el-option>
          </el-select>
        </div>
        <div class="margin_right_20">
          评价状态:&nbsp;
          <el-select v-model="evaluateStatus" style="width: 110px;">
            <el-option
              v-for="item in options2"
              :key="item.value2"
              :label="item.label"
              :value="item.value2"
            ></el-option>
          </el-select>
        </div>
        <div class="btn">
          <el-button type="primary" icon="el-icon-search" @click="get_orderList(1)">查询</el-button>
        </div>
      </div>

      <div class="query">
        <div class="start_time margin_right_20">
          创建时间(开始):&nbsp;
          <div class="block">
            <el-date-picker
              type="datetime"
              v-model="startTime"
              placeholder="选择日期时间"
              style="width:200px"
              value-format="yyyy-MM-dd HH:mm:ss"
            ></el-date-picker>
          </div>
        </div>
        <div class="end_time margin_right_20">
          创建时间(结束):&nbsp;
          <div class="block">
            <el-date-picker
              type="datetime"
              placeholder="选择日期时间"
              style="width:200px"
              v-model="endTime"
              default-time="23:59:59"
              value-format="yyyy-MM-dd HH:mm:ss"
            ></el-date-picker>
          </div>
        </div>
      </div>
      <div class="table">
        <el-table :data="orderList" style="width: 100%" height="548">
          <el-table-column prop="orderNo" label="订单编号" width="200"></el-table-column>
          <el-table-column prop="userNo" label="用户ID"></el-table-column>
          <el-table-column prop="userName" label="用户昵称"></el-table-column>
          <el-table-column prop="goodPosition" label="订单所属活动" width="120px"></el-table-column>
          <el-table-column prop="goodsName" label="商品名称" width="400px"></el-table-column>
          <el-table-column prop="amount" label="订单金额"></el-table-column>
          <el-table-column label="评价详情" width="200px">
            <template slot-scope="scope">
              <span @click="getMessage(scope.row.evaluateMessage)">{{scope.row.evaluateMessage}}</span>
              <el-dialog :visible.sync="dialogVisible">
                <el-input type="textarea" :rows="9" v-model="evaluateMessage"></el-input>
              </el-dialog>
            </template>
          </el-table-column>
          <el-table-column prop="evaluateStatus" label="评价状态"></el-table-column>
          <el-table-column prop="createtime" label="创建时间" width="200"></el-table-column>
          <el-table-column label="操作" width="130">
            <template slot-scope="scope">
              <el-button
                type="text"
                size="small"
                @click="jump_goods_status(scope.row.goodsEvaluateId,scope.row.evaluateStatus)"
              >{{scope.row.evaluateStatus=="隐藏"? "显示" :"隐藏"}}</el-button>
            </template>
          </el-table-column>
        </el-table>
        <pagination
          :currentPage="currentPage"
          :page="page"
          :total="total"
          :pageSize="pageSize"
          @change-current="currentChange"
          @change-size="sizeChange"
        ></pagination>
      </div>
    </div>
  </div>
</template>
<script>
import breadcrumb from "../../components/breadcrumb";
import pagination from "../../components/page";
import { mapActions } from "vuex";
export default {
  components: { breadcrumb, pagination },
  data() {
    return {
      currentPage: 1,
      pageSize: 10,
      page: 1,
      total: 0,
      dialogVisible: false,
      options1: [],
      options2: [
        { value2: "", label: "全部" },
        { value2: "1", label: "显示" },
        { value2: "2", label: "隐藏" }
      ],
      orderList: [],
      orderNo: "",
      userNo: "",
      // userNo: "",
      goodsName: "",
      positionId: "",
      evaluateStatus: "",
      startTime: "",
      endTime: "",
      evaluateMessage: ""
    };
  },
  created() {
    this.get_orderList();
    // 获取商品类型
    this.positions();
  },
  methods: {
    getMessage(evaluateMessage) {
      this.evaluateMessage = evaluateMessage;
      this.dialogVisible = true;
    },
    jump_goods_status(id, status) {
      // let data = {
      //   evaluateStatus: status,
      //   goodsEvaluateId: id
      // };
      var status1;
      if (status) {
        status1 = status == "显示" ? "2" : "1";
      } else {
        status1 = null;
      }

      let data = "evaluateStatus=" + status1 + "&goodsEvaluateId=" + id;
      this.$axios
        .post("/web_order/evaluate_updateStatus", data)
        .then(result => {
          if (result.data.status == 0) {
            if (result.data.data == true) {
              this.get_orderList();
              return this.$message({
                type: "success",
                message: "操作成功"
              });
            } else {
              return this.$message({
                type: "warning",
                message: "操作失败"
              });
            }
          }
        });
    },
    positions() {
      this.$axios.post("/web_goods_pos/list").then(res => {
        this.options1 = res.data.data;
        this.options1.unshift({ id: "", position: "全部" });
      });
    },
    sizeChange(val) {
      this.pageSize = val;
      this.currentPage = 1;
      this.get_orderList();
    },
    currentChange(val) {
      this.currentPage = val;
      this.get_orderList();
    },
    jump_order_detail(id) {
      localStorage.setItem("path", JSON.stringify(this.$route.path));
      localStorage.setItem(
        "pageMsg",
        JSON.stringify({
          currentPage: this.currentPage,
          pageSize: this.pageSize
        })
      );
      this.$router.push("/orderDetail?id=" + id);
    },
    jump_order_modify(id, status) {
      localStorage.setItem("path", JSON.stringify(this.$route.path));
      localStorage.setItem("status", JSON.stringify(status));
      this.$router.push("/orderModify?id=" + id);
    },
    get_orderList() {
      // let data = {
      //   orderNo: this.orderNo,
      //   userNo: this.userNo,
      //   goodsName: this.goodsName,
      //   positionId: this.positionId,
      //   evaluateStatus: this.evaluateStatus,
      //   startTime: this.startTime,
      //   endTime: this.endTime,
      //   current: this.currentPage,
      //   size: this.pageSize
      // };
      var data =
        "current=" +
        this.currentPage +
        "&size=" +
        this.pageSize +
        "&orderNo=" +
        this.orderNo +
        "&userNo=" +
        this.userNo +
        "&goodsName=" +
        this.goodsName +
        "&positionId=" +
        this.positionId +
        "&evaluateStatus=" +
        this.evaluateStatus +
        "&startTime=" +
        this.startTime +
        "&endTime=" +
        this.endTime;
      this.$axios.post("/web_order/evaluate_page", data).then(result => {
        if (result.data.status == 0) {
          this.orderList = result.data.data.records;
          this.total = result.data.data.total;
          this.page = result.data.data.pages;
          this.orderList.forEach(item => {
            if (item.evaluateStatus) {
              item.evaluateStatus =
                item.evaluateStatus == "1" ? "显示" : "隐藏";
            }
          });
        }
      });
    },
    // 校验结束时间
    verfy_startTime() {
      if (this.startTime) {
        this.timeCompare(1);
      }
    },
    //   校验结束时间
    verfy_endtime() {
      if (this.endTime) {
        this.timeCompare(2);
      }
    },

    timeCompare(flag) {
      //  flag  用于标记是清楚开始时间，还是清楚结束时间
      if (
        new Date(this.startTime).getTime() >= new Date(this.endTime).getTime()
      ) {
        if (flag == 1) {
          this.startTime = "";
        } else {
          this.endTime = "";
        }
        return this.$message({
          type: "warning",
          message: "'拼团创建时间-开始'必须小于'拼团创建时间-结束'"
        });
      }
    }
  }
};
</script>

<style lang="less" >
.ordermanage-container {
  @import "../../style/table.less";
  @import "../../style/content.less";
  display: flex;
  flex-flow: column;
  position: relative;
  height: 100%;
  .el-table .cell {
    white-space: pre-line !important;
  }
  .content {
    .query {
      .start_time {
        display: flex;
        align-items: center;
      }
      .end_time {
        display: flex;
        align-items: center;
      }
      .btn {
        .el-button {
          width: 70px;
        }
      }
    }
  }
}
</style>

